package leetcode_day._2021._202112._2131;

import java.util.Arrays;
import java.util.List;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/12/21 9:21
 * 一年中的第几天
 * 算法：数学 + 字符串
 */
public class _21_1154 {
    public static void main(String[] args) {
        System.out.println(new _21_1154().dayOfYear("2003-12-27"));
    }

    static List<Integer> days = Arrays.asList(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31);
    public int dayOfYear(String date) {
        String[] split = date.split("-");
        int year = Integer.parseInt(split[0]), month = Integer.parseInt(split[1]), day = Integer.parseInt(split[2]);
        for (int i = 1; i < month; i++) day += days.get(i - 1);
        if (month > 2 && (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))) ++day;
        return day;
    }

}
